// pages/defect/adjustment/main/craft/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    dataSource: [
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onAdd() {
      const dataSource = [...this.data.dataSource];
      dataSource.push({
        name: '',
        value: ''
      })
      this.setData({
        dataSource
      })
    },
    onInput(event) {
 
      const value = event.detail.value,
        {
          index,
          key
        } = event.currentTarget.dataset,
        dataSource = this.data.dataSource;
      dataSource[index][key] = value;
      this.setData({
        dataSource
      })
    },
    onRemove(event){
      const {
        index
      } = event.currentTarget.dataset,
      dataSource = this.data.dataSource;
      wx.showModal({
          title: '要移除此项吗？',
          success: res=>{
            if(res.confirm){
              dataSource.splice(index, 1);
              this.setData({
                dataSource
              })
            }
          }
      })
    }
  }
})